<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./js/vue2.js"></script>
</head>
<body>
    <div id="app">
        <father></father>
    </div>
    <template id="father">
        <div class="father">
            <h1>我是父组件 我叫{{fname}}</h1>
            <son></son>
            <daughter></daughter>
            <p>今天我儿子告诉我他有女朋友了 ，名字叫做{{erxifu}}</p>
        </div>
    </template>
    <template id="son">
        <div class="son">
            <h2>我是子组件之一，我叫做{{sname}}</h2>
            <input type="button" value="点击告诉" @click="tellname">
        </div>
    </template>
    <template id="daughter">
        <div class="daughter">
            <h3>我是子组件之一，我叫做{{dname}}</h3>
        </div>
    </template>
</body>
<script>
    // 创建事件总线的实例对象
    var bus = new Vue()
    // 父组件
    Vue.component('father',{
        template:"#father",
        data(){
            return {
                fname:"jack",
                erxifu:"??"
            }
        },
        mounted () {
            bus.$on('getname',(data)=>{
                this.erxifu=data;
            })
        },
        components: {
            'son':{
                template:"#son",
                data(){
                    return{
                        sname:"som",
                        gfname:'cuihua'
                    }
                },
                methods: {
                    tellname(){
                        bus.$emit('getname',this.gfname)
                    }
                }
            },
            'daughter':{
                template:"#daughter",
                data(){
                    return{
                        dname:'lucy'
                    }
                }
            }
        }
    })
    var vm = new Vue({
        el:"#app",
        data:{

        }
    })
</script>
</html>